//
//  UserInfoAlertView.m
//  StationManager
//
//  Created by 泽华伟业 on 17/3/13.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "UserInfoAlertView.h"

@interface UserInfoAlertView ()

///题目
@property (nonatomic,strong) UILabel *titleLabel;

///取消按钮
@property (nonatomic,strong) UIButton *cancelButton;
///确定按钮
@property (nonatomic,strong) UIButton *confirmButton;

@end
@implementation UserInfoAlertView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self titleLabel];
        [self userTextField];
        [self cancelButton];
        [self confirmButton];
        self.backgroundColor = RGBCOLOR(230, 230, 228);
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 8;
    }
    return self;
}

- (UILabel *)titleLabel{
    if (!_titleLabel ) {
        _titleLabel = [[UILabel alloc]init];
        [_titleLabel setTextColor:[UIColor whiteColor]];
        [_titleLabel setBackgroundColor:RGBCOLOR(116, 168, 229)];
        [_titleLabel setFont:[UIFont systemFontOfSize:19]];
        [_titleLabel setTextAlignment:NSTextAlignmentCenter];
        [_titleLabel setText:@"设置维护人员信息"];
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
            make.height.equalTo(self).dividedBy(4);
        }];
    }
    return _titleLabel;
}

- (UITextField *)userTextField{
    if (!_userTextField) {
        _userTextField = [[UITextField alloc]init];
        [self addSubview:_userTextField];
        _userTextField.layer.borderColor = [UIColor orangeColor].CGColor;
        _userTextField.layer.borderWidth = 2;
        [_userTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20*wl);
            make.right.equalTo(self.mas_right).offset(-20*wl);
            make.top.equalTo(_titleLabel.mas_bottom).offset(20*hl);
            make.height.mas_equalTo(35*hl);
        }];
    }
    return _userTextField;
}

- (UIButton *)cancelButton{
    if (!_cancelButton) {
        _cancelButton = [[UIButton alloc]init];
        [self addSubview:_cancelButton];
        [_cancelButton addTarget:self action:@selector(cancelButtonDidSelected:) forControlEvents:UIControlEventTouchUpInside];
        [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_cancelButton setBackgroundColor:[UIColor whiteColor]];
        [_cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10*wl);
            make.bottom.equalTo(self.mas_bottom).equalTo(self).offset(-8*hl);
            make.height.mas_equalTo(35*hl);
            make.width.equalTo(self).dividedBy(2.3);
        }];
    }
    return _cancelButton;
}

- (UIButton *)confirmButton{
    if (!_confirmButton) {
        _confirmButton = [[UIButton alloc]init];
        [self addSubview:_confirmButton];
        [_confirmButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_confirmButton setBackgroundColor:[UIColor whiteColor]];
        [_confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_confirmButton setTitle:@"确定" forState:UIControlStateNormal];
        [_confirmButton addTarget:self action:@selector(confirmButtonDIdSeleced:) forControlEvents:UIControlEventTouchUpInside];
        [_confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-10*wl);
            make.bottom.equalTo(_cancelButton);
            make.size.equalTo(_cancelButton);
        }];
    }
    return _confirmButton;
}

#pragma mark -- 按钮点击方法
- (void)cancelButtonDidSelected:(UIButton *)sender{
    //根据tag值找到半透明视图
    UIView *view = [self.window viewWithTag:170311];
    [view removeFromSuperview];
    [self removeFromSuperview];
}

//确定按钮点击
- (void)confirmButtonDIdSeleced:(UIButton *)sender{
    if (![_userTextField.text isEqualToString:@""]) {
        [USER_DEFAULT setObject:[NSString stringWithFormat:@"  %@",_userTextField.text] forKey:@"weihurenyuan"];
    }
    //根据tag值找到半透明视图
    UIView *view = [self.window viewWithTag:170311];
    [view removeFromSuperview];
    [self removeFromSuperview];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
